package com.ruoyi.system.service.equipment.impl;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.equipment.EquipmentCheckPlan;
import com.ruoyi.system.domain.equipment.EquipmentFighting;
import com.ruoyi.system.mapper.equipment.EquipmentFightingMapper;
import com.ruoyi.system.service.equipment.IEquipmentFightingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 消防设施Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-17
 */
@Service
public class EquipmentFightingServiceImpl implements IEquipmentFightingService
{
    @Autowired
    private EquipmentFightingMapper equipmentFightingMapper;

    /**
     * 查询消防设施
     * 
     * @param id 消防设施主键
     * @return 消防设施
     */
    @Override
    public EquipmentFighting selectEquipmentFightingById(Long id)
    {
        return equipmentFightingMapper.selectEquipmentFightingById(id);
    }

    /**
     * 查询消防设施列表
     * 
     * @param equipmentFighting 消防设施
     * @return 消防设施
     */
    @Override
    public List<EquipmentFighting> selectEquipmentFightingList(EquipmentFighting equipmentFighting)
    {
        if (StringUtils.isNotEmpty(equipmentFighting.getIds())) {
            equipmentFighting.setIdAry(Arrays.asList(equipmentFighting.getIds().split(",")));
        }

        return equipmentFightingMapper.selectEquipmentFightingList(equipmentFighting);
    }

    /**
     * 新增消防设施
     * 
     * @param equipmentFighting 消防设施
     * @return 结果
     */
    @Override
    public int insertEquipmentFighting(EquipmentFighting equipmentFighting)
    {
        equipmentFighting.setCreatedDate(new Date());
        equipmentFighting.setCreatedBy(SecurityUtils.getUsername());
        return equipmentFightingMapper.insertEquipmentFighting(equipmentFighting);
    }

    /**
     * 导入消防设施
     *
     * @param list 消防设施
     * @return 查询结果
     */
    @Override
    public String importHandler(List<EquipmentFighting> list, String loginUser) {
        if (StringUtils.isEmpty(list)) {
            throw new ServiceException("导入设备数据不能为空！");
        }
        list.forEach(e -> {
            e.setCreatedBy(loginUser);
            e.setCreatedDate(new Date());
        });
        equipmentFightingMapper.insertBatch(list);
        return "成功";
    }

    /**
     * 修改消防设施
     * 
     * @param equipmentFighting 消防设施
     * @return 结果
     */
    @Override
    public int updateEquipmentFighting(EquipmentFighting equipmentFighting)
    {
        equipmentFighting.setModifyDate(new Date());
        equipmentFighting.setModifyBy(SecurityUtils.getUsername());
        return equipmentFightingMapper.updateEquipmentFighting(equipmentFighting);
    }

    /**
     * 批量删除消防设施
     * 
     * @param ids 需要删除的消防设施主键
     * @return 结果
     */
    @Override
    public int deleteEquipmentFightingByIds(Long[] ids)
    {
        return equipmentFightingMapper.deleteEquipmentFightingByIds(ids);
    }

    /**
     * 删除消防设施信息
     * 
     * @param id 消防设施主键
     * @return 结果
     */
    @Override
    public int deleteEquipmentFightingById(Long id)
    {
        return equipmentFightingMapper.deleteEquipmentFightingById(id);
    }
}
